<template>
    <div>
        <van-field label='角色名' v-model="name"/>
         <van-button @click="add" color="linear-gradient(to right, #ff6034,#7232dd)">添加</van-button>

         <ul v-for="i in role">
             <li>{{i.name}}   <router-link :to="{'path':'/addresources','query':{'id':i.id}}">配置资源</router-link></li>
         </ul>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                name:'',
                role:[]
            }
        },
        methods:{
            add(){
                this.$axios.post('roleM',{name:this.name}).then(res=>{
                    if(res.data.code==200){
                         alert('添加成功')
                    }else{
                        alert('角色名已经存在')
                    }
                   
                })
            },
            getrole(){
                this.$axios.get('roleM').then(res=>{
                    this.role = res.data.list
                })
            },
        },
        mounted(){
            this.getrole()
        }
    }
</script>

<style scoped>

</style>